package com.hdax.search.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.function.Function;

public class Callable01 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        System.out.println("线程开始了");
        FutureTask<Integer> integerFutureTask = new FutureTask<>(new CallableText());
        new Thread(integerFutureTask).start();
        Integer integer = integerFutureTask.get();
        //等待整个线程池执行完成，获取返回结果
        //当前线程处于阻塞的状态
        System.out.println(integer);
        System.out.println("线程结束了");


        new Thread(()-> System.out.println("开启一个线程")).start();





    }

    public static class CallableText implements Callable<Integer> {

        @Override
        public Integer call() throws Exception {
            System.out.println("当前线程"+Thread.currentThread().getId());
            int i = 10/2;
            System.out.println("运行结果："+i);
            return i;
        }
    }
}
